function isSuccessFmt (val) {
  return val ? '成功' : '失败';
}
function isOrNoFmt (val) {
  if (val == 'true') {
    return '是';
  } else if (val == 'false') {
    return '否';
  } else {
    return '未知';
  }
}
function productEnv (val) {
  return (process.env.PRODUCT_URL || '') + val;
}

function engNumberFmt (val) {
  // 1234 return 1,234
  var str = val.toString();
  var reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
  return str.replace(reg, "$1,");
}

function tenFmt (val) {
  // 1 return 01
  return val < 10 ? '0' + val : val;
}

function percentFmt (val) {
  return (val * 100).toFixed(2) + '%';
}

export default {
  isSuccessFmt,
  isOrNoFmt,
  productEnv,
  engNumberFmt,
  tenFmt,
  percentFmt
};
